import router from "@/router";
import Local from "@/utils/local";
import type {LoginSubmitResponsePermissionTreeDTOListType} from "@/types/loginType.ts";
import {getTreeItem} from "@/utils";

// 判断操作列是否显示
export const shouldShowOperateColumn = (list: string[], len: number): LoginSubmitResponsePermissionTreeDTOListType | undefined | boolean => {
    if (list.length === len) {
        const menuName: string = router.currentRoute.value.name as string; // 获取当前菜单名称
        const menu: LoginSubmitResponsePermissionTreeDTOListType[] = JSON.parse(Local.localRead('menuList')); // 获取所有菜单列表
        const row = getTreeItem<LoginSubmitResponsePermissionTreeDTOListType, string>(menu, menuName, 'componentName', 'children'); // 在菜单列表中查找当前菜单
        // 如果当前菜单存在子菜单
        if (row?.children) {
            for (const str of list) {
                return row.children.find(item => item.status === '1' && item.perms === str);
            }
            return true;
        } else {
            // 如果当前菜单没有子菜单，返回 false
            return false;
        }
    }
};
